package frobagroup.controller.frontEnd;

import frobagroup.pagination.Pagination;
import frobagroup.services.frontEnd.HomeService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Tinsley on 2018/5/15.
 */
@RequestMapping("/webAPI/home")
@RestController
public class HomeController {

    @Autowired
    private HomeService homeService;


    @RequestMapping(value = "/unAuth/findCarousels", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findCarousels() throws Exception{
        return ResponseModel.success(homeService.findCarousels(),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/unAuth/findProductDetial/{pId}", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findProductDetial(@PathVariable String pId,HttpServletRequest request) throws Exception{
        return ResponseModel.success(homeService.findProductDetial(pId,request),
                Constants.RESPONSE_STATUS_SUCESS);
    }


    @RequestMapping(value = "/unAuth/findExtensionProducts", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findExtensionProducts(@RequestBody Pagination pagination) throws Exception{
        return ResponseModel.success(homeService.findExtensionProducts(pagination),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/unAuth/findProductsByConditions", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findProductsByConditions(@RequestBody Pagination pagination) throws Exception{
        return ResponseModel.success(homeService.findProductsByConditions(pagination),
                Constants.RESPONSE_STATUS_SUCESS);
    }


}
